﻿<Space>
    <SpaceItem>
        CheckStrictly: <Switch @bind-Checked="_checkStrictly" />
    </SpaceItem>
    <SpaceItem>
        ShowCheckedStrategy: 
        <RadioGroup @bind-Value="_showCheckedStrategy">
            <Radio RadioButton Value="TreeCheckedStrategy.ShowChild">ShowChild</Radio>
            <Radio RadioButton Value="TreeCheckedStrategy.ShowParent">ShowParent</Radio>
            <Radio RadioButton Value="TreeCheckedStrategy.ShowAll">ShowAll</Radio>
        </RadioGroup>
    </SpaceItem>
</Space>
<br />
<br />
<TreeSelect Style="width:100%;"
            DataSource="treeData"
            @bind-Values="@values"
            Placeholder="Please select"
            AllowClear
            TreeCheckable
            TreeCheckStrictly="_checkStrictly"
            ShowCheckedStrategy="_showCheckedStrategy"
            CheckOnClickNode
            TreeDefaultExpandAll
            ItemValue="node=> node.Key"
            ChildrenExpression="node=>node.DataItem.Children"
            TitleExpression="node=>node.DataItem.Title"
            KeyExpression="node=>node.DataItem.Key"
            IsLeafExpression="node=>node.DataItem.Children==null">
</TreeSelect>

@JsonSerializer.Serialize(values);

@code {
    private IEnumerable<string> values = new[] { "1" };
    TreeCheckedStrategy _showCheckedStrategy = TreeCheckedStrategy.ShowParent;
    bool _checkStrictly = false;

    Data[] treeData = new Data[]
    {
        new()
        {
            Title = "Node1",
            Key="1",
            Children = new Data[]
    {
                new()
                {
                    Title = "Child Node1",
                    Key="11",
                },
    }
        },
        new()
        {
            Title = "Node2",
            Key="2",
            Children = new Data[]
    {
                new()
                {
                    Title ="Child Node3",
                    Key="21"
                },
                new()
                {
                    Title ="Child Node4",
                    Key="22",
                },
                new()
                {
                    Title ="Child Node5",
                    Key="23",
                }
    }
        }
    };

    public class Data : ITreeData<Data>
    {
        public string Key { get; set; }
        public Data Value => this;
        public string Title { get; set; }
        public IEnumerable<Data> Children { get; set; }
    }
}